package day04;

import java.util.Random;
import java.util.Scanner;

//猜数字游戏
public class Guessing {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请猜一个数!");
        Random ran = new Random();

        int num = (int) (Math.random() * 1000 + 1);
        /*
        int num = ran.nextInt(100)+1;

         */
        System.out.println(num);

        int guess;
        do {
            guess = sc.nextInt();
            if (guess > num) {
                System.out.println("你猜的数太大了");
            } else if (guess < num) {
                System.out.println("你猜的数太小了");
            } else {
                System.out.println("恭喜你,猜对了");
            }
        } while (guess != num);

        /*
        执行过程:
            //300   200    250
            声明一个整形变量 guees猜
            猜=300   if判断大小  输出太大了
            猜=200   if判断大小  输出太小了
            猜+250   if判断大小  输出你猜对了

        * */


        /*
        int guess = sc.nextInt();

        while (guess != num){
            if (guess>num){
                System.out.println("你猜的数太大了");
            }else {
                System.out.println("你猜的数太小了");
            }
            guess =sc.nextInt();
        }
        System.out.println("恭喜你,你猜对了");

         */
    }
    /*
    执行过程:
        建立扫描器,定义一个num和为250进入循环while
        猜guess判断为true     if判断guess是否大于num和   为真输出为假输出else语句
        再次接受猜吧的数,重新进入循环,再次判断,但guess外false时循环结束,输出最后语句:你猜对了

    * */
}
